package com.paradigmcreatives.game;

import com.paradigmcreatives.game.listeners.ColorOnClickListener;
import com.paradigmcreatives.game.manager.UIManager;
import com.paradigmcreatives.game.ui.DoodleCanvas;
import com.paradigmcreatives.game.ui.WordList;
import com.paradigmcreatives.game.word.WordGenerator;

import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

public class DoodleGameActivity extends Activity {
	
    private static final String TAG = "DoodleGameActivity";

	/** Called when the activity is first created. */
	public DoodleCanvas doodleCanvas = null;
	
	public EditText keywordInput = null;
	public EditText keywordGuess = null;
	
	public Button nextTurn = null;
	
	public RelativeLayout mainLayout = null;
	public RelativeLayout bottomBar = null;
	public RelativeLayout face1 = null;
	public RelativeLayout face2 = null;
	public RelativeLayout face3 = null;
	public UIManager uiManager = null;
	
	public LinearLayout colorPalatte = null;
	
	
	public ImageView color1;
	public ImageView color2;
	public ImageView color3;
	public ImageView color4;
	public ImageView color5;
	public ImageView color6;
	public ImageView color7;
	public ImageView color8;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       Init();
       uiManager = UIManager.getInstance(DoodleGameActivity.this);
       uiManager.setUpListenersForUiElements();
    
    }

    /**
     * Initializes all the UI components 
     */
	private void Init() {
		Log.i(TAG, "Started Initiating UI ");
		setContentView(R.layout.main);
		
		new WordList(this).showDialog();
		
		doodleCanvas = (DoodleCanvas)findViewById(R.id.doodleCanvas);
		
		keywordInput = (EditText) findViewById(R.id.keywordInput);
		keywordGuess = (EditText) findViewById(R.id.keywordGuess);
		
		Typeface font1 = Typeface.createFromAsset(getAssets(), "Action_Man.ttf");
		keywordInput.setTypeface(font1, Typeface.NORMAL);
		keywordGuess.setTypeface(font1, Typeface.NORMAL);
		
		keywordInput.setEnabled(true);
		keywordInput.setFocusable(true);
		
		mainLayout = (RelativeLayout) findViewById(R.id.mainLayout);
		bottomBar = (RelativeLayout) findViewById(R.id.bottomBar);
		face1 = (RelativeLayout) findViewById(R.id.face1);
		face2 = (RelativeLayout) findViewById(R.id.face2);
		face3 = (RelativeLayout) findViewById(R.id.face3);
		
		colorPalatte = (LinearLayout) findViewById(R.id.palatte);
		
		
		nextTurn = (Button) findViewById(R.id.nextturn);
		
		color1 = (ImageView) findViewById(R.id.color1);
		color2 = (ImageView) findViewById(R.id.color2);
		color3 = (ImageView) findViewById(R.id.color3);
		color4 = (ImageView) findViewById(R.id.color4);
		color5 = (ImageView) findViewById(R.id.color5);
		color6 = (ImageView) findViewById(R.id.color6);
		color7 = (ImageView) findViewById(R.id.color7);
		color8 = (ImageView) findViewById(R.id.color8);
		
		color1.setOnClickListener(new ColorOnClickListener(this));
		color2.setOnClickListener(new ColorOnClickListener(this));
		color3.setOnClickListener(new ColorOnClickListener(this));
		color4.setOnClickListener(new ColorOnClickListener(this));
		color5.setOnClickListener(new ColorOnClickListener(this));
		color6.setOnClickListener(new ColorOnClickListener(this));
		color7.setOnClickListener(new ColorOnClickListener(this));
		color8.setOnClickListener(new ColorOnClickListener(this));
		
	}
	
	@Override
	protected void onPause() {
		super.onPause();
		uiManager.unRegisterAllListeners();
	}
	
	@Override
	public void onBackPressed() {
		uiManager.unRegisterAllListeners();
		System.exit(0);
	}
}